<template>
  <div>
    <div v-for="(item,index) in newList" :id="item.id">
      {{item.title}}-{{item.createTime}} <a href="javascript:void(0)" @click="delRow(item.id,index)">删除</a>
    </div>

  </div>
</template>

<script>
  import { getAction } from '@/api/manage'

  export default {
    name: 'JSelectDepartModal',
    props:['value'],
    data(){
      return {
        newList:[],
        oldList:[],
        selectList:[]
      }
    },
    methods:{
      delRow(id,index){
        this.newList.splice(index,1)
        var result=''
        if(this.newList && this.newList.length>0){
          for(var item of this.newList){
            if(result.indexOf(item.id)==-1){
              result+=item.id
              result+=','
            }
          }
        }
        this.$emit('change',result)
      },
      async loadData(){
        if(this.titleIds){
          let ids = this.titleIds+','
          let param = {'id': ids}
          getAction('/temple.news/templeNews/getMultiNews', param).then((res)=>{
            this.newList = res.result
          })
        }
      }
    },
    watch:{
      value(val,old){
        console.log("xxxxxxxxxxxxxxxx")
        console.log(this.value)
        if(this.value){
          console.log("into")
          let array = this.value.split(',')
          this.oldList = array
          let ids = array+','
          let param = {'id': ids}
          getAction('/temple.news/templeNews/getMultiNews', param).then((res)=>{
            console.log(res)
            this.newList = res.result
            console.log(this.newList)
          })
        }
      }
    },
    created(){


    },
    model: {
      prop: "value",
      event: "change"
    }


  }
</script>

<style lang="less" scoped>

</style>
